﻿using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkExtension;
using EntityFrameworkExtension.Interface;
using MainProcessor.Caching;
using MainProcessor.Interface;
using NUnit.Framework;
using Rhino.Mocks;

namespace Test.Main.Caching
{
    [TestFixture]
    public class RepositoryFlushTests 
    {
        private IEfContext efContext;
        private IRepositoryFlush repositoryFlush;
        [SetUp]
        public void SetUp()
        {
            efContext = MockRepository.GenerateMock<IEfContext>();
            repositoryFlush = new RepositoryFlush(efContext);
        }

        [TearDown]
        public void Teardown()
        {
            efContext.VerifyAllExpectations();
        }

        [Test]
        public void WillCallCreateWhenNotFound()
        {
            efContext.Expect(x => x.GetObjectList<MutableReferenceTable1>()).Return(Enumerable.Empty<MutableReferenceTable1>().ToList()).Repeat.Once();

            efContext.Expect(x => x.AddToObjectList(Arg<MutableReferenceTable1>.Matches(y => y.Id == InputId)));
            efContext.SaveChanges();
            var results = repositoryFlush.CreateGuidIdMapping<MutableReferenceTable1>(InputId);

            Assert.IsNotNull(results);
        }


        private const int InputId = 42;


    }
}
